package com.young.rpc.http;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;


public class CallBackRequestBody implements RequestBody {
    /** 回调url */
    @JsonIgnore
    private String url;

    private String jobUniqCode;
    private String traceId;
    private Integer jobNodeNum;
    private Integer jobNodeIndex;

    private String callBackNode;

    private Integer status;
    private Long duration;
    private String errorMessage;
    /** 客户端版本号 */
    private String clientVersion;

    @Override
    public String getUrl() {
        return url;
    }

    @Override
    public String getBody() {
        Gson gson = new Gson();
        return gson.toJson(this,this.getClass());
    }

    @Override
    public Map<String, Object> getParameter() {
        Map<String, Object> parameter = new HashMap<>(16);
        parameter.put("jobUniqCode",jobUniqCode);
        parameter.put("traceId",traceId);
        parameter.put("jobNodeIndex",jobNodeIndex);
        parameter.put("jobNodeNum",jobNodeNum);
        parameter.put("callBackNode",callBackNode);
        parameter.put("status",status);
        parameter.put("duration",duration);
        parameter.put("errorMessage",errorMessage);
        parameter.put("clientVersion",clientVersion);
        return parameter;
    }

    public String getJobUniqCode() {
        return jobUniqCode;
    }

    public String getTraceId() {
        return traceId;
    }

    public String getCallBackNode() {
        return callBackNode;
    }

    public Integer getJobNodeNum() {
        return jobNodeNum;
    }

    public Integer getJobNodeIndex() {
        return jobNodeIndex;
    }

    public Integer getStatus() {
        return status;
    }

    public Long getDuration() {
        return duration;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public CallBackRequestBody(Builder builder) {
        this.url = builder.url;
        this.jobUniqCode = builder.jobUniqCode;
        this.traceId = builder.traceId;
        this.callBackNode = builder.callBackNode;
        this.jobNodeNum = builder.jobNodeNum;
        this.jobNodeIndex = builder.jobNodeIndex;
        this.status = builder.status;
        this.duration = builder.duration;
        this.errorMessage = builder.errorMessage;
        this.clientVersion = builder.clientVersion;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private String url;
        private String jobUniqCode;
        private String traceId;
        private String callBackNode;
        private Integer jobNodeNum;
        private Integer jobNodeIndex;
        private Integer status;
        private Long duration;
        private String errorMessage;
        private String clientVersion;

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder jobUniqCode(String jobUniqCode) {
            this.jobUniqCode = jobUniqCode;
            return this;
        }

        public Builder traceId(String traceId) {
            this.traceId = traceId;
            return this;
        }

        public Builder callBackNode(String callBackNode) {
            this.callBackNode = callBackNode;
            return this;
        }

        public Builder jobNodeNum(Integer jobNodeNum) {
            this.jobNodeNum = jobNodeNum;
            return this;
        }

        public Builder jobNodeIndex(Integer jobNodeIndex) {
            this.jobNodeIndex = jobNodeIndex;
            return this;
        }

        public Builder status(Integer status) {
            this.status = status;
            return this;
        }

        public Builder duration(Long duration) {
            this.duration = duration;
            return this;
        }

        public Builder errorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
            return this;
        }

        public Builder clientVersion(String clientVersion) {
            this.clientVersion = clientVersion;
            return this;
        }

        public CallBackRequestBody build() {
            return new CallBackRequestBody(this);
        }

    }
}
